package com.jin.lazytool.entity;


import com.github.kwhat.jnativehook.mouse.NativeMouseEvent;
import com.jin.lazytool.utils.JinUtils;
import org.luaj.vm2.LuaTable;

import java.awt.*;

public class MouseReleasedEvent extends MouseClickEvent {

    public MouseReleasedEvent(){}

    public MouseReleasedEvent(NativeMouseEvent mouseEvent){
        super(mouseEvent);
    }
    @Override
    public int execute(Robot robot, int index) throws InterruptedException,NoSuchMethodException {
        if(luaFLag){
            LuaTable lua = JinUtils.evalLua(getLua(), getTime());
            boolean exeFlag = lua.get("exeFlag").toboolean();
            if(exeFlag){
                Thread.sleep(lua.get("time").tolong());
                int x = lua.get("x").toint();
                int y = lua.get("y").toint();
                robot.mouseMove(x, y);
                robot.mouseRelease(getButton());

            }
        }else{
            Thread.sleep(getTime());
            robot.mouseMove(getX(), getY());
            robot.mouseRelease(getButton());

        }
        return index;

    }
    @Override
    String initDescVal() {
        return "鼠标松开";
    }
}
